<%@ page import="dao.Lesson" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="service.CourseService" %>
<%@ page contentType="text/html;charset=UTF-8"  %>
<%
    String nickname=request.getSession().getAttribute("nickname").toString();
    int cid=Integer.parseInt(request.getParameter("cid")) ;
    List<Lesson> lessons= CourseService.getLessonsByCid(cid);  // 获取lessons
    System.out.println(lessons.size());
//    String imagePath=request.getParameter("imagePath");
    String imagePath= CourseService.getCourseImagePath(cid);
    int sectionId=-1;
    if(lessons.size()>0){
        sectionId=lessons.get(lessons.size()-1).sectionId;
    }
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>视频管理</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="css/iconfont.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/manage-videos.css">
</head>
<body>
    <!--头部-->
    <div class="top">
        <div class="w">
            <div class="top-left">
                <img src="images/Q-logo.png" alt="">
            </div>
            <div class="top-center">
                <input placeholder="搜索你感兴趣的课程" id="wd">
                <script>
                    function search() {
                        var wd=document.getElementById('wd');
                        window.location.href="search-result.jsp?wd="+wd.value;
                    }
                </script>
                <button class="iconfont" onclick="search()">&#xe63c;</button>
            </div>
            <div class="top-right">
                <ul>
                    <a href="index.jsp"><li>首页</li></a>
                    <li onclick="alert('请退出登录')">登录注册</li>
                    <a href="self.jsp"><li class="current">个人主页</li></a>
                </ul>
            </div>
        </div>
    </div>

    <div class="top-self" style="background-image: url(images/bg1.jpg); background-size: cover;">
        <div class="w">
            <img class="pro" src="images/pro1.jpg" alt="123"/>
            <div class="text">
                <h2><%=nickname%>同学，欢迎登录</h2>
                <h4>构成我们学习最大障碍的是已知的东西，而不是未知的东西。——贝尔纳</h4>
            </div>
            <a href="QuitLogin"><button class="log_out">退 出 登 录</button></a>
        </div>
    </div>
    <!--中部-->
    <div class="main">
        <div class="main-top-bar">
            <div class="w">
                <a href="index.jsp">首页&nbsp>&nbsp</a>
                <a href="self.jsp">个人中心&nbsp>&nbsp</a>
                <a href="manage-videos.jsp" class="current">视频管理</a>
            </div>
        </div>
        <div class="main-upload">
            <a class="iconfont" href="upload-videos.jsp?sectionId=<%=sectionId%>&cid=<%=cid%>">
                <span>&#xe642;</span>
                <span>上传视频</span>
            </a>
        </div>
        <div class="main-content">
            <div class="w2">
                <ul class="videos" id="videos">
                <%
                    for(int i=0;i<lessons.size();++i){
                        Lesson lesson=lessons.get(i);
                 %>
                        <li>
                            <div class="video-left">
                                <img src=<%=imagePath%>>
                            </div>
                            <div class="video-center">
                                <!--视频名称-->
                                <p class="course-name"><%=lesson.lessonName%></p>
                                <!--机构单位-->
                                <p class="course-from">陕西师范大学</p>
                                <!--视频时长-->
                                <p class="course-time">15:53</p>
                            </div>
                            <div class="video-right">
                                <a href="add_test.jsp?lid=<%=lesson.lid%>"><button class="btn1">添加测试</button></a>
                                <button class="btn2">删除</button>
                            </div>
                        </li>
                <%
                    }
                %>
                </ul>
            </div>
        </div>
    </div>

    <!--尾部-->
    <div class="bottom">
        <div class="bottom-board">
            <span>丰富的视频资源帮助学生更好地学习</span>
            <span>基于认知负荷的多少推荐课程</span>
            <span>方案多多，适合每一位学生</span>
        </div>

    </div>

    <script>
        window.onload = function () {

            var videos = $('videos').children;
            console.log(videos);

            for(var i=0; i<videos.length; i++){
                var btn = videos[i].getElementsByClassName('btn2')[0];
                // console.log(btn);

                //监听按钮的点击
                btn.onmousedown = function () {
                    var r = confirm('你确定要删除视频吗？');
                    console.log(btn.parentNode.parentNode);
                    if(r)
                        this.parentNode.parentNode.remove();
                }
            }
        };

        function $(id) {
            return typeof id === "string" ? document.getElementById(id) : null;
        }
    </script>
</body>
</html>